package com.ocom.srvpaccess.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.master.EntityMjAppVerInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.redis.aspect.CacheRedisAspect;
import com.ocom.srvpaccess.dao.IDaoMjAppVerInfo;
import com.ocom.srvpaccess.service.MjAppVerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MjAppVerInfoServiceImpl extends ServiceImpl<IDaoMjAppVerInfo, EntityMjAppVerInfo> implements MjAppVerInfoService {



    @Autowired
    private IDaoMjAppVerInfo mjAppVerInfo;

    //apkUrl = mj_app_ver_info . apk_file_url
    @CacheRedisAspect(prefix = "selectAppVerUrl",element = {"appVer"},deadline = 120L)
    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public String selectAppVerUrl(String appVer) {
        System.out.println(appVer);
        QueryWrapper<EntityMjAppVerInfo> query = Wrappers.query();
        query.eq("app_ver",appVer).last("limit 1");
        EntityMjAppVerInfo entityMjAppVerInfo = mjAppVerInfo.selectOne(query);
        if (entityMjAppVerInfo == null){
            return null;
        }
        return entityMjAppVerInfo.getApkFileUrl();
    }

    //从门禁设备app版本信息表mj_app_ver_info查找apk_type=2、app_ver=mj_device_info . app_ver_tab的记录
    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public EntityMjAppVerInfo selectSinglechipAppVerInfo(String appVerTab) {
        QueryWrapper<EntityMjAppVerInfo> query = Wrappers.query();
        query.eq("apk_type",2).eq("app_ver",appVerTab).last("limit 1");
        return mjAppVerInfo.selectOne(query);
    }
}
